﻿using BBCore.Core.Models.BaseModels;
using BBCore.Core.Models.Samples;
using BootstrapBlazor.Components;
using FreeSql.Aop;
using Microsoft.AspNetCore.Components;

namespace BBCore.Server.PublicComponentBase
{
    /// <summary>
    /// 主从明细表Crud导入导出模板公共部分提取基类
    /// </summary>
    public class Master_Detail_ComponentBase : Template_ComponentBase
    {
        protected override async Task OnInitializedAsync()
        {
            // 基类已处理审计，无需重复代码
            await base.OnInitializedAsync();

            // 子类特有初始化（若有）

            //Username = await GetLoginUserNameService.GetLoginUserNameAsync(authStateProvider);
            //await base.OnInitializedAsync();
            ////配置 FreeSql 审计值拦截器
            //freeSql.Aop.AuditValue += (s, e) =>
            //{
            //    var currentUser = Username;
            //    var now = DateTime.Now;
            //    if (e.Object is BaseModel modelBase)//检查类型，判断当前操作的实体是否需要审计
            //    {
            //        if (e.AuditValueType == AuditValueType.Insert)
            //        {
            //            if (e.Property.Name == nameof(BaseModel.CREATION_DATE))
            //                e.Value = now;
            //            //扩展:如果需要更复杂的审计（如记录操作日志），可在基类中添加额外方法                    
            //            if (e.Property.Name == nameof(BaseModel.CREATED_BY))
            //                e.Value = currentUser;
            //        }
            //        else if (e.AuditValueType == AuditValueType.Update)
            //        {
            //            if (e.Property.Name == nameof(BaseModel.LAST_UPDATED_BY))
            //                e.Value = currentUser;
            //            if (e.Property.Name == nameof(BaseModel.LAST_UPDATED_DATE))
            //                e.Value = now;
            //        }
            //    }
            //};
        }


    }
}
